package day4.com.isoftstone.thread.test;

public class SyncStack {
	private int index=0;
	private char buffer[]=new char[6];

	public void push (char c){
		while (index==buffer.length){
			try{
				this.wait();
			}
			catch(InterruptedException e){}
		}
		this.notify();
		buffer[index]=c;
		index++;
	}

	public  char pop(){
		while (index==0){
			try{
				this.wait();
			}
			catch(InterruptedException e){}
		}
		this.notify();
		index--;
		return buffer[index];
	}
	
	public static void main (String args[]){
		SyncStack stack =new SyncStack();
		Runnable source=new Producer(stack);
		Runnable sink =new Consumer(stack);

		Thread t1=new Thread(source);
		Thread t2=new Thread(sink);
		t1.start();
		t2.start();
	}
}